package com.spring.mvc.http.jcex;

import java.math.BigInteger;

public class CryptorXRSA {
	private static byte[] n = { 109, 79, 8, -3, -127, 8, 49, 70, -63, -32, -40,
			-50, -114, 88, 48, 10, 22, 13, 73, -55, -9, 77, 100, -108, -4, -77,
			-68, 57, -92, 40, -82, -77, 48, 98, -50, -17, 105, 89, 126, -110,
			96, -126, 13, -25, -96, 68, 62, -6, 88, -37, 32, 55, 4, -5, -87,
			83, -11, -85, 124, -121, -94, 113, 5, 72, -23, -73, -41, -13, 98,
			-78, -9, -109, -88, -1, -6, 63, -47, 103, 57, 22, 82, -67, -69, 91,
			97, 121, 0, 66, 41, -70, -83, 52, -15, 61, 34, -31, -112, -96, 52,
			-32, -72, 70, 57, 53, 42, 75, -66, -12, -56, -19, 105, 57, -3,
			-106, 18, 99, -62, -54, -55, -38, -2, 115, 25, 100, 57, -76, 73,
			-18, -60, -61, 90, -98, -85, -81, 109, -57, 21, 20, 64, 22, 95,
			-123, 35, 94, 38, -107, 93, -102, 109, -47, -2, 94, 73, -73, -117,
			-109, 37, 10, 81, -46, -25, 95, -119, -62, -86, 16, -102, 127, 114,
			41, -87, -100, -13, -96, 84, -58, -4, -4, 44, 50, -111, 45, -127,
			-64, 112, -106, -15, -112, -71, 87, 120, -40, 53, -111, -86, -5,
			-56, -39, 37, 39, 45, 21, -6, 71, 54, 57, 119, -64, -24, 21, 17,
			-1, -20, -99, 90, -6, 8, 75, -76, 126, -46, -107, 13, -113, 95,
			-82, 20, -12, 12, -82, -36, 98, 46, 17, -76, -117, 98, 110, 5, -40,
			33, 120, 13, -107, -32, -48, -106, -8, -120, -7, 27, -78, -102, 88,
			98, -107 };
	private static BigInteger N = new BigInteger(n);
	private static BigInteger E = BigInteger.valueOf(65537L);
	private static byte[] d = { 101, -10, 47, 96, -88, -105, -57, -65, 68, -30,
			67, -38, -119, 20, -31, -38, -58, -81, 38, -127, 106, 89, -102,
			-43, 14, -45, 105, 100, 43, 40, 119, -83, 86, 25, 21, 6, 101, -78,
			-63, 74, 49, 19, -97, 124, -52, 22, 92, -40, -111, 65, -11, 78,
			-35, 43, 18, -53, -22, -127, 71, -20, 13, 46, 119, -53, -121, -105,
			-95, -84, -70, 8, 78, -64, 66, 8, 100, -102, 90, -18, 122, 101,
			-60, 80, -113, 15, -78, 96, 120, 73, 63, 59, -114, -115, -81, -23,
			99, 60, 28, -8, 19, -38, -6, -119, 38, -101, -35, 20, 66, -49, 123,
			13, 89, -10, 106, 1, 46, -82, 55, -23, -119, 88, -23, -72, -37,
			-102, -115, -23, 10, 124, -101, 102, 81, -38, -39, -116, -92, -50,
			-94, 2, -122, -2, -56, 109, -20, -65, 0, -58, 81, -110, 46, 72, 9,
			32, -14, 107, -11, -14, 40, 0, 98, 46, -25, 35, 45, 57, -23, -72,
			52, 27, 94, -110, 106, -26, -45, 27, 10, -79, -44, -45, 25, -108,
			12, -57, 66, -71, -78, -68, -72, 112, -99, 96, 76, -65, -47, -101,
			92, -17, -22, 47, 57, -89, 43, 52, 124, -46, -99, 121, -73, 50,
			113, 26, -115, -126, 23, 75, 41, -27, 28, 125, 70, -38, 72, 81,
			-72, -67, 0, -61, 3, -41, 94, -109, 42, -73, -32, -51, 86, 16, 46,
			76, 115, 64, -125, 89, 10, 50, 97, -22, 18, 16, -41, 126, 113, 19,
			103, -33, 3, -111 };
	private static BigInteger D = new BigInteger(d);

	public byte[] encryptD(byte[] message) {
		BigInteger M = new BigInteger(message);
		BigInteger C = M.modPow(D, N);
		return C.toByteArray();
	}

	public byte[] encryptE(byte[] message) {
		BigInteger M = new BigInteger(message);
		BigInteger C = M.modPow(E, N);
		return C.toByteArray();
	}

	public byte[] decryptD(byte[] message) {
		BigInteger C = new BigInteger(message);
		BigInteger M = C.modPow(D, N);
		return M.toByteArray();
	}

	public byte[] decryptE(byte[] message) {
		BigInteger C = new BigInteger(message);
		BigInteger M = C.modPow(E, N);
		return M.toByteArray();
	}
}